package com.snopy.designPattern.chainOfResponsibility.impl;

import com.snopy.designPattern.chainOfResponsibility.inter.Middleware;
import lombok.extern.slf4j.Slf4j;

/**
 * @author snopy
 * @version 1.0.0
 * @classname UserExistsMiddleware
 * @description
 * @email 77912204@qq.com
 * @date 2022/03/04 13:15
 */
@Slf4j
public class UserExistsMiddleware extends Middleware {
    private Server server;

    public UserExistsMiddleware(Server server) {
        this.server = server;
    }

    @Override
    public boolean check(String username, String password) {
        if (!server.hasUsername(username)){
            log.info("This username is not registered!");
            return false;
        }
        if (!server.isValidPassword(username,password)){
            log.info("This password is wrong!");
            return false;
        }
        return checkNext(username,password);
    }
}
